package com.tom.jmgd.controller;

import com.tom.jmgd.common.HttpClientUtil;
import com.tom.jmgd.core.entity.ResultEntity;
import com.tom.jmgd.core.enums.ResultEnum;
import com.tom.jmgd.dao.H2InterviewDao;
import com.tom.jmgd.dao.huobanSyncDataDao;
import com.tom.jmgd.entity.param.H2Interview;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testController2")
public class TestController2 {
    @Autowired
    private H2InterviewDao h2InterviewDao;

    @Autowired
    private huobanSyncDataDao huobanSyncDataDao1;

    @Resource
    private HttpServletResponse response;


    @RequestMapping("/test")
    public ResultEntity syncJMGDFactory() {
        H2Interview h2Interview = h2InterviewDao.selectByOpenId("oOQ7pv1FIhOIFR4p2sSXjLk6XaYA");
        List<String> i = huobanSyncDataDao1.getSynTableName();
        System.out.println("1111");
        return new ResultEntity(ResultEnum.SAVE_SUCCESS,null);
    }

    @GetMapping("/")
    public ModelAndView index(Model model){
        model.addAttribute("name", "dalaoyang");
        return new ModelAndView("index");
    }




    @GetMapping(value = "/getImage")
    public void getImage() throws IOException {
        OutputStream os = null;
        try {
//        读取图片
            BufferedImage image = ImageIO.read(new FileInputStream(new File("D:\\1.png")));
            response.setContentType("image/png");
            os = response.getOutputStream();

            if (image != null) {
                ImageIO.write(image, "png", os);
            }
        } catch (IOException e) {
            //log.error("获取图片异常{}",e.getMessage());
        } finally {
            if (os != null) {
                os.flush();
                os.close();
            }
        }
    }

    public static void main(String[] args){
       Map map = HttpClientUtil.doGet("https://zyxiao.jmgdyf.com/api/pay/start");
       System.out.println(map.get("msg"));
//        Date currDate = new Date();
//        SimpleDateFormat df = new SimpleDateFormat("HHmm");
//        String hour = df.format(currDate);
//        int h = Integer.valueOf(hour);
//        System.out.println(h);
    }
}
